<template>
  <div class="login-container">
    <!-- <img class="back_img" :src="url" alt> -->
    <div class="login-box">
      <div class="title">
        <!-- <img src="../assets/img/logo.png" alt> -->
        管理员操作平台
      </div>

      <div class="user_login">
        <span>管理员登录</span>
        <span>Control_Login</span>
      </div>

      <el-form ref="loginFormRef" :model="loginForm" :rules="loginFormRules">
        <el-form-item prop="username">
          <el-input v-model="loginForm.username">
            <i slot="prefix" class="iconfont icon-user"></i>
          </el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input show-password type="password" v-model="loginForm.password">
            <i slot="prefix" class="iconfont icon-3702mima"></i>
          </el-input>
        </el-form-item>
        <el-row>
          <el-col>
            <!-- <span class="rem_me" @click="lock = !lock"> -->
            <!-- <i :class="{ali_iconfont:true,ali_iconduigou:true,lock_y_n:lock?true:false}"></i> -->
            <!-- <span :class="{lock_y_n:lock?true:false}">记住我</span> -->
            <!-- </span> -->
            <el-button class="determined" type="primary" @click="Submit_application">登录</el-button>
            <!-- <el-button type="info">重置</el-button> -->
          </el-col>
        </el-row>
      </el-form>

      <div class="footer">欢迎登录管理员平台</div>
    </div>
  </div>
</template>

<script>
import Qs from "qs";
export default {
  data() {
    return {
      // 用户名密码数据
      // 密码要MD5加密   npm install --save js-md5
      loginForm: {
        username: "admin",
        password: "ryzh.3212255"
      },
      //   验证规则
      loginFormRules: {
        // required:非空  message:错误提示  trigger:触发校验机制
        username: [
          { required: true, message: "请输入用户名称", trigger: "blur" }
        ],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }]
      }
    };
  },

  methods: {
    async Submit_application() {
      this.$refs.loginFormRef.validate(async valid => {
        if (valid) {
          let obj = {
            username: this.loginForm.username,
            password: this.$md5(this.loginForm.password)
          };

          let { data: res } = await this.$http.post(
            "/user/login",
            Qs.stringify(obj)
          );

          if (res.status != 0) return this.$message.error("密码或用户名错误！");
          if (res.data.type != 1)
            return this.$message.error("您的账号权限，无法登陆管理员系统");
          console.log(res);
          // 存储token
          window.sessionStorage.setItem("token", res.token);
          this.$router.push("/home");
          const loading = this.$loading({
            lock: true,
            text: "Loading",
            spinner: "el-icon-loading",
            background: "rgba(0, 0, 0, 0.7)"
          });
          setTimeout(() => {
            loading.close();
          }, 2000);
        }
      });
    }
  }
};
</script>

<style lang='less' scoped>
.back_img {
  width: 100%;
  height: 100%;
}

.lock_y_n {
  color: #007ee5;
}
.footer {
  font-size: 14px;
  color: #007ee5;
  text-align: center;
  line-height: 58px;
  height: 58px;
  position: absolute;
  bottom: 0px;
  width: 100%;
  background-color: #e1e4ed;
  border-radius: 0px 0px 10px 10px;
}
.el-input--prefix .el-input__inner {
  padding-left: 40px !important;
}
.login-container {
  // background-color: #05bdf9;
  background: url(../assets/img/bg1.jpg) no-repeat;
  background-size: 100%;
  height: 100%;
  overflow: hidden;

  //   background-color: #1f794c;
  .login-box {
    width: 450px;
    height: 344px;
    // background-color: #fff;
    background-image: linear-gradient(160deg, #132946 30%, #e1e3ee 80%);
    border-radius: 10px;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0px 5px 5px 5px rgba(8, 8, 8, 0.2);
    .el-form {
      position: absolute;
      //   bottom: 0;
      top: 70px;
      width: 100%;
      padding: 20px;
      box-sizing: border-box;
      margin-bottom: 30px;

      .iconfont {
        padding-left: 15px;
      }
      .determined {
        width: 100%;
        background-color: #007ee5;
        font-size: 16px;
      }
      .rem_me {
        // 禁止用户选择文字
        user-select: none;
        color: #ccc;
        font-size: 16px;
        float: left;
        cursor: pointer;
        line-height: 40px;
        i {
          font-size: 20px;
        }
      }
    }
    .title {
      font-size: 40px;
      color: #fff;
      transform: translateY(-200%);
      text-align: center;
    }
    .user_login {
      margin-top: -20px;
      color: #429ced;
      display: flex;
      justify-content: space-between;
      padding: 0px 20px;
      :first-child {
        font-size: 26px;
      }
    }
  }
}
</style>
